﻿// JavaScript Document
function JoinSnatch(id){
    //判断购买数量是否小于限购数量
    var price = $("input[name='price']")[0].value;
    var path = $("#pathnow")[0].value;
    var maxprice = $("#maxprice")[0].value;
    var minprice = $("#minprice")[0].value;
    
    if(parseInt(price) > parseInt(maxprice) || parseInt(price) < parseInt(minprice) || isNaN(price) || price <= 0){
        alert("您的出价超出了有效的出价范围");
        return false;
    }
    
    var url = path + "snatch.aspx?act=joinsnatch&price=" + price + "&id=" + id;
    window.location.href= url;
}

function InitSnatchData(id){
    var path = $("#pathnow")[0].value;
	
	var url = path + "snatch.aspx?act=winuser&id=" + id;
	//Ajax请求
	$("#winusername").load(url,hiddenorshow); 
	
	url = path + "snatch.aspx?act=winprice&id=" + id;
	//ajax请求
	$("#winprice").load(url);
	
	url = path + "snatch.aspx?act=windate&id=" + id;
	//ajax请求
	$("#windate").load(url);
}

function hiddenorshow(){
	if($("#winusername")[0].innerHTML == "--"){
		$("#actarea")[0].style.display = "";
	}else{
		if($("#winusername")[0].innerHTML == username){
			$("#buyarea")[0].style.display = "";
		}
	}
}

function BuySnatch(){
	if($("#winusername")[0].innerHTML == username){
		var url = path + "cart.aspx?id=" + $("#productid")[0].value + "&act=buy&count=1&snatchid="+cid+"&price=" + $("#winprice")[0].innerHTML;
		window.location.href = url;
	}	
}